from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import render
from django.db import connection
import requests
import json
import os
from django.http import HttpResponseRedirect
from django.urls import reverse

class File_object:
    def __init__(self, file_name, title, content, score):
        self.file_name = file_name
        self.title = title
        self.content = content
        self.score = score


def index(request):
    print("访问首页 index.html  ")
    api_request = requests.get("http://www.baidu.com")
    resp = {
        'title':'    title 标题  >>>  ',
        "key": api_request.content
    }
    obj_0 = File_object("file_00", "Docker 安装 Java JDK 8" , "Docker 的旧版本被称为 docker，docker.io 或 docker-engine 。如果已安装，请卸载它们：" , 56)
    obj_1 = File_object("file_11", "JavaScript 教程" , "JavaScript 是 Web 的编程语言。所有现代的 HTML 页面都可以使用 JavaScript。" , 12)
    print(obj_0.title)
    return render(request,'index/inde.html', {'data': json.dumps(obj=obj_0.__dict__,ensure_ascii=False)})



@csrf_exempt
def ajax_post_test(request):
    if request.method == 'POST':
        print("ajax test =============================")
        print("ajax test =============================")
        return HttpResponse("哈哈哈哈哈哈哈哈哈", content_type="application/json")
    else:
        return HttpResponse("哈哈哈哈哈哈哈哈哈", content_type="application/json")


def get_aaa(request, aaa):
    # 使用aaa参数的值进行处理
    print(aaa) 
    print(aaa) 
    return HttpResponse(aaa, content_type="application/json")